package com.piggy.logi.sys.controller;

import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.bo.*;
import com.piggy.logi.sys.service.ILogiCarrierStatisticsService;
import com.piggy.logi.sys.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 承运统计Controller
 *
 * @author fengxy
 * @date 2023/10/17 21:28
 **/
@Api(value = "承运统计控制器", tags = {"承运统计"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/carrier/statistics")
public class LogiCarrierStatisticsController extends BaseController {

    private final ILogiCarrierStatisticsService iLogiCarrierStatisticsService;

    /**
     * 服务商统计
     */
    @ApiOperation("服务商统计")
    //@SaCheckPermission("sys:carrier:dept:carrier")
    @PostMapping("/dept")
    public TableDataInfo<LogiDeptStatisticsVo> dept(@Validated @RequestBody LogiDeptStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiCarrierStatisticsService.deptStatisticsPage(bo);
    }

    /**
     * 服务商统计导出
     */
    @ApiOperation("服务商统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:carrier:statistics:dept:export')")
    @LogiLog(title = "承运统计", businessType = BusinessType.EXPORT)
    @PostMapping("/dept/export")
    public void deptExport(@Validated @RequestBody LogiDeptStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiDeptStatisticsVo> list = iLogiCarrierStatisticsService.deptStatisticsList(bo);
        ExcelUtil<LogiDeptStatisticsVo> util = new ExcelUtil<>(LogiDeptStatisticsVo.class);
        util.exportExcel(response, list, "服务商统计");
    }

    /**
     * 承运商统计
     */
    @ApiOperation("承运商统计")
    //@SaCheckPermission("sys:carrier:statistics:carrier")
    @PostMapping("/carrier")
    public TableDataInfo<LogiCarrierStatisticsVo> carrier(@Validated @RequestBody LogiCarrierStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiCarrierStatisticsService.carrierStatisticsPage(bo);
    }

    /**
     * 承运商统计导出
     */
    @ApiOperation("承运商统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:carrier:statistics:carrier:export')")
    @LogiLog(title = "承运统计", businessType = BusinessType.EXPORT)
    @PostMapping("/carrier/export")
    public void carrierExport(@Validated @RequestBody LogiCarrierStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiCarrierStatisticsVo> list = iLogiCarrierStatisticsService.carrierStatisticsList(bo);
        ExcelUtil<LogiCarrierStatisticsVo> util = new ExcelUtil<>(LogiCarrierStatisticsVo.class);
        util.exportExcel(response, list, "司机统计");
    }

    /**
     * 司机统计
     */
    @ApiOperation("司机统计")
    //@SaCheckPermission("sys:carrier:statistics:driver")
    @PostMapping("/driver")
    public TableDataInfo<LogiDriverStatisticsVo> driver(@Validated @RequestBody LogiDriverStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiCarrierStatisticsService.driverStatisticsPage(bo);
    }

    /**
     * 司机统计导出
     */
    @ApiOperation("司机统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:carrier:statistics:driver:export')")
    @LogiLog(title = "承运统计", businessType = BusinessType.EXPORT)
    @PostMapping("/driver/export")
    public void driverExport(@Validated @RequestBody LogiDriverStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiDriverStatisticsVo> list = iLogiCarrierStatisticsService.driverStatisticsList(bo);
        ExcelUtil<LogiDriverStatisticsVo> util = new ExcelUtil<>(LogiDriverStatisticsVo.class);
        util.exportExcel(response, list, "司机统计");
    }

    /**
     * 车辆统计
     */
    @ApiOperation("车辆统计")
    //@SaCheckPermission("sys:carrier:statistics:car")
    @PostMapping("/car")
    public TableDataInfo<LogiCarStatisticsVo> car(@Validated @RequestBody LogiCarStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiCarrierStatisticsService.carStatisticsPage(bo);
    }

    /**
     * 车辆统计导出
     */
    @ApiOperation("车辆统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:carrier:statistics:car:export')")
    @LogiLog(title = "承运统计", businessType = BusinessType.EXPORT)
    @PostMapping("/car/export")
    public void carExport(@Validated @RequestBody LogiCarStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiCarStatisticsVo> list = iLogiCarrierStatisticsService.carStatisticsList(bo);
        ExcelUtil<LogiCarStatisticsVo> util = new ExcelUtil<>(LogiCarStatisticsVo.class);
        util.exportExcel(response, list, "车辆统计");
    }

    /**
     * 线路统计
     */
    @ApiOperation("线路统计")
    //@SaCheckPermission("sys:carrier:statistics:line")
    @PostMapping("/line")
    public TableDataInfo<LogiLineStatisticsVo> line(@Validated @RequestBody LogiLineStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiCarrierStatisticsService.lineStatisticsPage(bo);
    }

    /**
     * 线路统计导出
     */
    @ApiOperation("线路统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:carrier:statistics:line:export')")
    @LogiLog(title = "承运统计", businessType = BusinessType.EXPORT)
    @PostMapping("/line/export")
    public void lineExport(@Validated @RequestBody LogiLineStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiLineStatisticsVo> list = iLogiCarrierStatisticsService.lineStatisticsList(bo);
        ExcelUtil<LogiLineStatisticsVo> util = new ExcelUtil<>(LogiLineStatisticsVo.class);
        util.exportExcel(response, list, "线路统计");
    }
}
